package com.work.app.controller;

import com.baidu.xuper.api.Account;
import com.baidu.xuper.api.XuperClient;

import com.baidu.xuper.config.Config;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

/**
 * @author hjj
 * @Time 2024/3/8 18:19
 */
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/chains")
public class XuperController {
    @Value("${xuperchain.client-url}")
    private String url;//开放网络
    @Value("${xuperchain.keys}")
    private String key;//私钥文件存储位置
    @Value("${web.upload-path}")
    private String filePath;//文件存储位置
    @Value("${web.assess-path}")
    private String assessPath;//返回给前端的头路径

    @Autowired
    private HttpServletRequest request;
    private XuperClient client;
    @PostConstruct
    public void Init(){//初始化
        //设置配置文件
        Config.setConfigPath(key+"sdk.yaml");
        //初始化客户端
        client = new XuperClient(url);
    }
    @ApiOperation("获取账户信息")
    @GetMapping("/account")
    public Account getAccount() throws Exception {
        Account account = Account.getAccountFromFile(key+"46468468468","182419");
        account.setContractAccount("XC5659359071648698@xuper");
        return account;
    }

}
